package net.devkit.core.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 * 提供友好的错误页面　
 * @author shizeyuan
 *
 */
@Controller
@Scope("request")
@RequestMapping("/error/")
public class ErrorController extends BaseController{
	
	/**
	 * 显示一个自定义的错误页
	 * @param message 对request传入一个给用户的提示
	 * @return
	 */
	@RequestMapping(value="message",method=RequestMethod.GET)
	public ModelAndView message(HttpServletRequest request){
		String message = (String) request.getAttribute("message");
		ModelAndView mav = new ModelAndView("error/show-error");
		mav.addObject("errorMessage",message);
		return mav;
	}
	
	/**
	 * 显示一个自定义信息的错误页
	 * @param errorMessage 错误提示信息
	 * @return ModelAndView 对象
	 */
	public static ModelAndView showPage(String errorMessage){
		ModelAndView mav = new ModelAndView("error/show-error");
		mav.addObject("errorMessage",errorMessage);
		return mav;
	}
	
	/**
	 * 404错误页
	 * @return
	 */
	@RequestMapping(value="404",method=RequestMethod.GET)
	public ModelAndView fileNotFound() {
		ModelAndView mav = new ModelAndView("error/show-error");
		mav.addObject("errorMessage","您访问的地址不存在！");
		return mav;
	}
}
